<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/publicPage.jsp"%>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>手机用户管理</title>
    <%@ include file="/publicIcon.jsp"%>
    <%@ include file="/publicLigerUI.jsp"%>
    <%@ include file="/publicGridJS.jsp"%>
    <script type="text/javascript">
        function itemclick(item)
        {
            alert(item.text);
        }
        var gridManager,win1 ;
        $(function ()
        {
            //布局
            $("#layout").ligerLayout({ leftWidth: 190, height: '80%',heightDiff:-34,space:4 });
            gridManager =
                $("#maingrid").ligerGrid({
                    height:'100%',
                    checkbox: true,
                    width:'100%',
                    columns: [
                        { display: 'id', name: 'id',hide:true,width: '0%'},
                        { display: '用户随机id', name: 'puserId',hide:true,width: '0%' },
                        { display: '用户名', name: 'puserName', width: '49.4%' },
                        { display: '用户号码', name: 'phoneNum', width: '49.4%' },
                    ],url:'/rest/message/phoneUserList',  pageSize:30 ,rownumbers:true,
                    //单击事件
                    onSelectRow:function(column, rowindex){
                        //alert(column.remark);
                        //alert(rowindex);
                    },
                    //双击行调到修改页面(获得ID当参数)
                    onDblClickRow:function(column, rowindex){
                        f_edit(column.id);
                    },
                    toolbar: { items: [
                            { text: '添加', click: function(item){
                                    f_Create();
                                }, icon: 'add' },
                            { line: true },
                            { text: '修改', click: function(item){
                                    f_Update();
                                }, icon: 'modify' },
                            { line: true },
                            { text: '删除', click: function(item){
                                    f_Delete();
                                }, icon:'delete'},
                            { line: true },
                        ]
                    }
                });
            $("#pageloading").hide();
        });


        //添加
        function f_Create()
        {
            win1 = $.ligerDialog.open({
                url: '/rest/message/doAddPhoneUser',
                title:"添加手机用户信息",
                width: 550,
                height:180,
                showMax: false,
                showToggle: true,
                showMin: false,
                isResize: true,
                slide: false
            });
        }
        //修改
        function f_Update()
        {
            var selRow = gridManager.getSelecteds();//返回选中行数，如果选中多于一行提示:不能同时修改多行！
            if(selRow.length>=2){
                $.ligerDialog.warn('您已选中多行数据,请确定需要修改的一行记录!');
                return false;
            }
            //如果没有选，则提示：请选中一行!
            var selected = gridManager.getSelected();
            if (!selected) {
                $.ligerDialog.error('请选中一行!');
                return;
            }
            win1 = $.ligerDialog.open({
                url: '/rest/message/phoneUserById?id='+selected.id,
                title:"修改信息",
                width: 550,
                height:180,
                showMax: false,
                showToggle: true,
                showMin: false,
                isResize: true,
                slide: false
            });
        }
        //双击行后调到修改页面,按传过来的ID
        function f_edit(id)
        {
            win1 = $.ligerDialog.open({
                url: '/rest/message/phoneUserById?id='+id,
                title:"修改信息",
                width: 550,
                height:180,
                showMax: false,
                showToggle: true,
                showMin: false,
                isResize: true,
                slide: false
            });
        }
        //删除
        function f_Delete()
        {
            //如果没有选，则提示：请选中一行!
            var selected = gridManager.getSelected();
            if (!selected) {
                $.ligerDialog.error('请选中一行!');
                return;
            }
            $.ligerDialog.confirm('你确定要删除吗?', function (yes){
                var selRow = gridManager.getSelecteds();//返回选中多行
                var id="";
                for(var i=0;i<selRow.length;i++){
                    id+=selRow[i].id+",";
                }
                if(yes){
                    $.ajax({ url: "/rest/message/phoneUserDel?id=" +id,
                        type: "post",
                        contentType:"charset=utf-8",
                        success: function(result){
                            gridManager.loadData();
                            $.ligerDialog.success('操作成功!');
                        },
                        error: function (request) {
                            window.parent.nodialog();
                        }
                    });
                }
            });
        }

        //grid刷新
        function loadData(){
            gridManager.loadData();
        }

        //关闭子窗口
        function closeDialog(){
            if(win1){win1.close();}
        }

        //成功操作
        function okdialog(){
            $.ligerDialog.success('操作成功!');
        }

        //失败操作
        function nodialog(){
            $.ligerDialog.error('操作失败!');
        }

        //关闭子窗口from
        function closeFrom(){
            win1.close();
        }
        //按条件查询
        $(function(){
            $("#Button1").ligerButton({
                click: function () {
                    //重置查询页数，从第一页开始
                    gridManager.set({ page: 1, newPage: 1 });
                    //设置Ajax参数
                    gridManager.setParm("puserName", $("#txtKey").val());
                    //重新请求
                    gridManager.loadData(gridManager.url);
                }
            });
        });
    </script>
</head>
<body>
<div id="layout">
    <div  title="信息列表" />
        <ul>
            <li style="margin:10px">
                用户名：
                <input class="input" name="txtKey" type="text" id="txtKey" ltype="text" />&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="submit"  value="查询" id="Button1" class="l-button l-button-submit" />
            </li>
        </ul>
        <div id="maingrid"></div>
    </div>
    <div style="display: none;">
    </div>
</div>
</body>
</html>